package com.ruoyi.life.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.omp.api.domain.FeOffice;
import com.ruoyi.life.service.IFeOfficeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 厂房/办公楼费用Controller
 *
 * @author cjie
 * @date 2021-09-17
 */
@Api(tags = "办公费用")
@RestController
@RequestMapping("/feOffice")
public class FeOfficeController extends BaseController {
    @Autowired
    private IFeOfficeService feOfficeService;

    /**
     * 查询厂房/办公楼费用列表
     */
    @ApiOperation(value="查询厂房-办公楼费用列表", notes="查询厂房-办公楼费用列表")
    @PreAuthorize(hasPermi = "life:feOffice:list")
    @GetMapping("/list")
    public TableDataInfo list(FeOffice feOffice) {
        startPage();
        List<FeOffice> list = feOfficeService.selectFeOfficeList(feOffice);
        return getDataTable(list);
    }

    /**
     * 导出厂房/办公楼费用列表
     */
    @ApiOperation(value="导出厂房/办公楼费用列表", notes="导出厂房/办公楼费用列表")
    @PreAuthorize(hasPermi = "life:feOffice:export")
    @Log(title = "厂房/办公楼费用", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FeOffice feOffice) throws IOException {
        List<FeOffice> list = feOfficeService.selectFeOfficeList(feOffice);
        ExcelUtil<FeOffice> util = new ExcelUtil<FeOffice>(FeOffice.class);
        util.exportExcel(response, list, "厂房/办公楼费用数据");
    }
    /**
     * 获取厂房/办公楼费用详细信息
     */
    @ApiOperation(value="获取厂房/办公楼费用详细信息", notes="获取厂房/办公楼费用详细信息")
    @PreAuthorize(hasPermi = "life:feOffice:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(feOfficeService.selectFeOfficeById(id));
    }

    /**
     * 新增厂房/办公楼费用
     */
    @ApiOperation(value="新增厂房/办公楼费用", notes="新增厂房/办公楼费用")
    @PreAuthorize(hasPermi = "life:feOffice:add")
    @Log(title = "厂房/办公楼费用", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FeOffice feOffice) {
        return toAjax(feOfficeService.insertFeOffice(feOffice));
    }

    /**
     * 修改厂房/办公楼费用
     */
    @ApiOperation(value="修改厂房/办公楼费用", notes="修改厂房/办公楼费用")
    @PreAuthorize(hasPermi = "life:feOffice:edit")
    @Log(title = "厂房/办公楼费用", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FeOffice feOffice) {
        return toAjax(feOfficeService.updateFeOffice(feOffice));
    }

    /**
     * 删除厂房/办公楼费用
     */
    @ApiOperation(value="删除厂房/办公楼费用", notes="删除厂房/办公楼费用")
    @ApiImplicitParam(name = "ids", value = "厂房/办公楼费用ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "life:feOffice:remove")
    @Log(title = "厂房/办公楼费用", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(feOfficeService.deleteFeOfficeByIds(ids));
    }
}
